import { ElLoading } from 'element-plus';

const num = 0;
const defaultOptions = {
  fullscreen: true,
  lock: true,
  text: '加载中...',
  background: 'rgba(0, 0, 0, 0)',
};
export default class SingleLoading {
  static getInstance(options = {}) {
    SingleLoading._instance = ElLoading.service({
      ...defaultOptions,
      ...options,
    });
  }

  static show(options = {}) {
    // if ( 0 == num ) {
    SingleLoading.getInstance(options);
    // }
    // num++
  }

  // static hide() {
  //   if ( 0 >= num ) return num = 0
  //   num--
  //   if ( 0 == num && SingleLoading._instance ) {
  //     setTimeout(() => {
  //       SingleLoading._instance.close()
  //     }, 100 );
  //   }
  // }
  static hide() {
    // if ( 0 >= num ) return num = 0
    // num--
    if (SingleLoading._instance) {
      setTimeout(() => {
        SingleLoading._instance.close();
      }, 100);
    }
  }
}
